package com.gurumades.jsonform.shared.dispatch.validators;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.gurumades.jsonform.shared.dispatch.JsonHelper;

public class CoreFormItemValidators implements FormItemValidator {
	List<FormItemValidator> validators = new ArrayList<FormItemValidator>();
	
	JsonHelper jshelper = ValidatorHelper.getJsonHelper();
	
	public CoreFormItemValidators() {
		validators.add(new RequiredValidator());
		validators.add(new AllowedValuesValidator());
	}
	
	@SuppressWarnings("rawtypes")
	@Override
	public void validate(Object item, Map<String, Object> values,
			ValidatorHelper helper) {
		
		for (FormItemValidator validator : validators) {
			Map wrapped = jshelper.wrapItem(item);
			if (validator.supportType((String)wrapped.get("type"))) {
				validator.validate(item, values, helper);
			}
			
		}
	}

	@Override
	public boolean supportType(String type) {
		return true;
	}

}
